<?php
/**
 * obj class
 * This class is a generically useful method of dealing with data as objects
 *
 * @package SMUOI
 * @subpackage Smernel
 * @subpackage obj
 * @since 0.1
 * @version $Revision: 1 $
*/
	class obj{
	
		/**
		* Constructor.
		* arguments may be omitted, a single indexed array, or alternating set key, value, key, value<br />
		* the following expressions are the same:<br />
		* <code>
		* 	new obj(array('key'=>'value', 'anotherkey'=>'another value'));
		* 	new obj('key', 'value', 'anotherkey', 'another value');
		* </code>
		* @param mixed 
		*/
		function __construct($a=null){
			if(is_null($a)) return;
			if(is_scalar($a)) return $this->set_list(func_get_args());
			foreach($a as $b=>$c) $this->$b = $c;
		}
		
		/**
		* Getter.
		* @param mixed key
		* @return mixed
		*/
		function get($k){
			if(isset($this->$k)) return $this->$k;
		}
		
		/**
		* Setter.  Accepts same arguments as {@link __construct}
		* @param mixed
		*/
		function set($a){
			if(is_null($a)) return;
			if(is_scalar($a)) return $this->set_list(func_get_args());
			foreach($a as $b=>$c) $this->$b = $c;
		}	
		
		/**
		* Sets indexed array of the form key, value, key, value
		* @param array
		*/
		function set_list(array $a){
			while(!empty($a)){
				$k = array_shift($a);
				$v = array_shift($a);
				if(empty($k)) continue;
				$this->$k = $v;
			}
		}
		
		/**
		* Turns all non-scalar members into instances of this class
		* @return obj
		*/
		function objectify(){
			foreach($this as $k=>$v){
				if(is_null($v) || is_scalar($v)) continue;
				if(!$v instanceof obj) $this->$k = new obj($v);
				$this->$k->objectify();
			}
			return $this;
		}
	}


